import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import Autoprefixer from "autoprefixer";
import Tailwindcss from "tailwindcss";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
// https://vitejs.dev/config/
export default defineConfig({
  css: {
    postcss: {
      plugins: [Tailwindcss, Autoprefixer],
    },
  },
  plugins: [
    vue({
      script: {
        defineModel: true,
      },
    }),
    Components({
      resolvers: [NaiveUiResolver()],
    }),
    AutoImport({
      include: [
        // 包含哪些文件。
        /\.[tj]sx?$/,
        /\.vue$/,
        /\.vue\?vue/,
      ],
      // global imports to register
      imports: [
        // 插件预设支持导入的api
        "vue",
        "vue-router",
        "pinia",
        // 自定义导入的api
        {
          "naive-ui": [
            "useDialog",
            "useMessage",
            "useNotification",
            "useLoadingBar",
          ],
        },
      ],
      dts: "./auto-imports.d.ts", // 生成在src路径下路径名为 auto-import.d.ts的声明文件
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  base: "./",
  build: {},
  server: {
    host: "0.0.0.0",
    port: 3000,
    proxy: {
      "/api": {
        target: "http://192.168.1.63:5600",
      },
    },
  },
});
